package com.training.android.customlist;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class CustomListActivity extends Activity {
	/** Called when the activity is first created. */

	ArrayList<Character> CartoonList = new ArrayList<Character>();
	CustomListBaseAdapter adapter;
	ListView listView;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		getData();
		listView = (ListView) findViewById(R.id.list);
		adapter = new CustomListBaseAdapter(this, CartoonList);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Toast.makeText(getApplicationContext(), CartoonList.get(position).getName(), Toast.LENGTH_SHORT).show();
			}
		});
	}

	private void getData() {
		Character c = new Character();
		c.setName("Luffy");
		c.setImage(getResources().getDrawable(R.drawable.luffy));
		CartoonList.add(c);
		
		c = new Character();
		c.setName("Zoro");
		c.setImage(getResources().getDrawable(R.drawable.zoro));
		CartoonList.add(c);		
	}
}